/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.opensource.jdom.taggen.util;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.opensource.jdom.taggen.Tag;

/**
 *
 * @author sergio.valdez
 */
public class TagUtil {

    public static final String   LOW_GUIDE    = "_";
    public static final String   DBL_LOW_GUIDE= "__";
    public static final String   MEDIUM_GUIDE = "-";

    public static String getStandarTagName(Tag tag) {
        Settings settings = null;

        try {
            SettingsUtil.createDefaultProps(tag.getClass()
                    .getPackage().toString());
            settings = SettingsUtil.createSettings(tag.getClass()
                    .getPackage().toString());
        } catch (IOException ex) {
            Logger.getLogger(TagUtil.class.getName())
                    .log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TagUtil.class.getName())
                    .log(Level.SEVERE, null, ex);
        }
        
        String replaceLWFrom  = LOW_GUIDE;
        String replaceLWTo    = MEDIUM_GUIDE;
        boolean lowercased = true;

        if (settings != null) {
            replaceLWFrom   = settings.getAttReplaceLowguideFrom();
            replaceLWTo     = settings.getAttReplaceLowguideTo();
            lowercased      = settings.isAttLowercased();
        }

        String result = tag.getClass().getSimpleName()
                .replaceAll(replaceLWFrom, replaceLWTo);

        if (lowercased) {
            result = result.toLowerCase();
        } else {
            result = Utils.getNameAsJavaStandar(result);
        }

        return result;
    }

    
}
